﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WF.Model;
using WF.DAL;

namespace WF.BusinessObject
{
    public class Operate : BOBase<OperateEntity, DAL.Operate>
    {
        #region 构造函数

        public Operate() : base() { }
        public Operate(WFDBDataContext DataContext)
            : base(DataContext)
        {

        }
        #endregion

        #region 实现基类abstract方法
        /// <summary>
        /// 实现基类的GetById abstract方法
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public override OperateEntity GetById(string ID)
        {
            var obj = DataContext.Operates.SingleOrDefault(o => o.OperateID == ID);
            return new OperateEntity(obj);
        }
        #endregion

        public List<Module> GetAllModules()
        {
            var objs = from a in DataContext.Operates group a by a.ModelName into b select new Module(b.Key, b.ToList());
            return objs.ToList();
        }

        public List<OperateEntity> GetOperatesByModule(string ModelName)
        {
            var objs = from a in DataContext.Operates where a.ModelName == ModelName select new OperateEntity(a);
            return objs.ToList();
        }

        public OperateEntity GetByName(string Name)
        {
            var obj = DataContext.Operates.FirstOrDefault(o => o.OperateName == Name);
            return new OperateEntity(obj);
        }

        public OperateEntity GetByOperateNo(string OperateNo)
        {
            var obj = DataContext.Operates.FirstOrDefault(o => o.OperateNo == OperateNo);
            return new OperateEntity(obj);
        }
    }
}
